<?php
// View for admin - form fields
require_once WACT_ROOT.'controller/controller.inc.php';
require_once WACT_ROOT .'controller/form.inc.php';
require_once WACT_ROOT.'view/view.inc.php';
require_once WACT_ROOT .'view/formview.inc.php';

require_once APP_ROOT . 'view/common/layout.formview.php';
require_once APP_ROOT . 'view/common/layout.view.php';

require_once 'model/common/user.php';
require_once 'model/common/form.php';
require_once 'model/common/categories.php';
require_once 'model/common/date.php';


class FormShowView extends LayoutFormView {

    function FormShowView($TemplateFile) {
        parent :: LayoutFormView($TemplateFile);
    }

    function prepare(&$controller, &$request, &$responseModel) {
    	parent::prepare($controller, $request, $responseModel);
        
		$this->Template->set('SITE_CSS',Site::getSiteTemplateCSS());
		$this->Template->set('SITE_BASE',Site::getSiteTemplateBase());
		$this->Template->set('SITE_TITLE',Site::getTitle());
 


        $form_id = $responseModel->get('form_id');
        if (!$form_id) $form_id = $request->getParameter();
        $record =& FormModel::getRecord($form_id);
        if (is_null($record)) {
           return 'notfound';
        }
        $responseModel->merge($record->export());

        $list =& FormFieldModel::getFormFields($form_id);

        $list_updated=array();

        $list->reset();
        $total = $list->getRowCount();
        $i = 0;
        while ($list->next()) {

        	$dataspace = $list->export();

            $form_id = $list->get('form_id');
            $field_id = $list->get('field_id');
            $order =  $list->get('order');

            //prepare options array
            $options = $list->get('options');
            $arr_options =& FormFieldModel::getOptionsAsArray($options);
            $dataspace['options_array'] =  $arr_options;
            $dataspace['order'] =  $order;

            $type = $list->get('type');
            $type_show = FormFieldModel::getFieldsTypeName($type);
            $dataspace['type_show'] =  $type_show;

            switch ($type) {
                       case 0: // text single line
                         $dataspace['type_text_single'] =  1;
                         break;
                       case 1:
                         $dataspace['type_text_multiple'] =  1;
                         break;
                       case 2:
                         $dataspace['type_select_single'] =  1;
                         break;
                       case 3:
                         $dataspace['type_select_multiple'] =  1;
                         break;
                       case 4:
                         $dataspace['type_radio'] =  1;
                         break;
                       case 5:
                         $dataspace['type_checkbox'] =  1;
                         break;

                     }



            //print_r($dataspace);  print '<br>';
            $list_updated[$field_id] = $dataspace;
            $i++;
        }

        $list_source_updated =& new ArrayDataSet($list_updated);
        $this->Template->setChildDataSource('List', $list_source_updated);
        return;

    }

}


?>